<%--
  User: Shengzhao Li
  Date: 13-8-6
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>Sprint</title>

    <link href="${contextPath}/js/web/bootstrap/datepicker/datepicker.css" rel="stylesheet"/>
    <script src="${contextPath}/js/web/bootstrap/datepicker/bootstrap-datepicker.js"></script>

    <script src="${contextPath}/js/web/ckeditor/ckeditor.js"></script>
</head>
<body>
<div class="row">
    <hr/>
</div>
<form:form commandName="sprintFormDto" id="sprintForm">
    <form:hidden path="guid"/>
    <div class="row sprint-form">
        <div class="span8 well">
            <fieldset>
                <legend>Sprint</legend>
                <table class="width100">
                    <tr>
                        <td colspan="2">
                            <label for="name">Sprint name</label>
                            <form:input path="name" id="name" placeholder="Sprint name" required="true" cssClass="span4"
                                        maxlength="255"/>
                            <form:errors path="name" cssClass="label label-warning"/>
                            <span class="help-block">Sprint name is unique, max length: 255.</span>
                            <form:hidden path="existName"/>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="startDate">Start date</label>

                            <div class="input-append date" id="startDate">
                                <form:input path="startDate" placeholder="Start date" cssClass="span2" readonly="true"
                                            required="true"/>
                                <span class="add-on"><i class="icon-th"></i></span>
                            </div>
                            <form:errors path="startDate" cssClass="label label-warning"/>
                            <span class="help-block">Start date must be after today</span>
                        </td>
                        <td>
                            <label for="deadline">Deadline</label>

                            <div class="input-append date" id="deadline">
                                <form:input path="deadline" placeholder="Deadline" cssClass="span2" readonly="true"
                                            required="true"/>
                                <span class="add-on"><i class="icon-th"></i></span>
                            </div>
                            <form:errors path="deadline" cssClass="label label-warning"/>
                            <span class="help-block">Deadline must be after the start date</span>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <label for="description">Description</label>
                            <form:textarea path="description" cssClass="ckeditor" id="description"/>
                        </td>
                    </tr>
                </table>
            </fieldset>
        </div>
        <div class="span3 well">
            <fieldset>
                <legend>Select backlogs</legend>
            </fieldset>
            <ul class="unstyled" id="backlogUl">
                <c:if test="${empty sprintFormDto.backlogs}" var="emptyBacklogs">
                    <li>
                        <label>No available backlogs</label>
                    </li>
                </c:if>
                <c:if test="${not emptyBacklogs}">
                    <c:forEach items="${sprintFormDto.backlogs}" var="b" varStatus="s">
                        <li>
                            <label class="checkbox">
                                <input type="checkbox" name="backlogs[${s.index}].guid"
                                       value="${b.guid}" ${b.selected?'checked':''} ${b.disabled?'disabled':''} /> ${b.name}
                                (<strong
                                    class="estimateTime ${b.selected?'backlogEstTime':''}">${b.estimateTime}</strong>)
                                <c:if test="${b.disabled}">
                                    <input type="hidden" name="backlogs[${s.index}].guid" value="${b.guid}"/>
                                </c:if>
                            </label>
                                <%--Use the hiddens for bind values after validation failed--%>
                            <form:hidden path="backlogs[${s.index}].name"/>
                            <form:hidden path="backlogs[${s.index}].estimateTime"/>
                            <form:hidden path="backlogs[${s.index}].selected"/>
                            <form:hidden path="backlogs[${s.index}].disabled"/>
                        </li>
                    </c:forEach>
                    <li>
                        <div class="badge badge-info sprint-backlog-budget" id="budgetTimes">Budget :
                            <strong>${sprintFormDto.budgetBacklogsTime}</strong> hour(s)
                        </div>
                        <form:hidden path="budgetBacklogsTime"/>
                    </li>
                </c:if>
            </ul>

        </div>
    </div>
    <div class="row">
        <div class="span5 offset2">
            <form:hidden path="addTask" id="addTask"/>
            <button type="submit" class="btn btn-success btn-large" addTask="false"><i class="icon-plus icon-white"></i>
                Save
            </button>
            <button type="submit" class="btn btn-info btn-large" addTask="true"><i class="icon-plus icon-white"></i>
                Save & Create task
            </button>
            <a href="../sprint_overview" class="btn btn-link">Cancel</a>
        </div>
    </div>
</form:form>
<script type="text/javascript">
    $(function () {
        var sprintForm = new SprintForm();
        sprintForm.initialDatePicker('${sprintFormDto.today}');
    });
</script>
</body>
</html>